;:poke56,128:clr
;:sys36864
	;.opt oo
	*= 32768
	jmp init
	jmp directory
	jmp holmax
open	=$ffc0
setnam	=$ffbd
setpar	=$ffba
close	=$ffc3
getx	=$b7f1
drive	=8
clrchn	=$ffcc
chkin	=$ffc6
work	=13
comm	=15
write	=$ffd2
chkout	=$ffc9
strout	=$ab1e
next	=2
input	=$ffcf
buffer	=$8f00
quote	=212
revers	=199
cr	=13
scr	=141
status	=$90
tmp	=4
axout	=$bdcd
space	=$ab3f
return	=$aad7
illquan	=$b248
direct	.byte "#"
diskinit	.byte "i0"
cmdstr	.byte "u1:13 0 "
track	.byt 0,0," "
sektor	.byt 0,0,255
buftxt	.byte "b-p 13 0"
	.byt 0
dirtxt	.byte "$0"
wechs	.byt 1,18,25,31
sekt	.byt 21,19,18,17
opendir	lda #comm
	tay
	ldx #drive
	jsr setpar
	lda #2
	lda #<diskinit
	ldy #>diskinit
	jsr setnam
	jsr open
	lda #work
	tay
	ldx #drive
	jsr setpar
	lda #1
	ldx #<direct
	ldy #>direct
	jsr setnam
	jmp open
clsdir	lda #work
	jsr close
	lda #comm
	jmp close
numbasc	ldx #"0"
	sec
numb1	sbc #10
	bcc numb2
	inx
	bcs numb1
numb2	adc #"9"+1
	rts
sendcmd	lda track
	jsr numbasc
	stx track
	sta track+1
	lda sektor
	jsr numbasc
	stx sektor
	sta sektor+1
	ldx #comm
	jsr chkout
	ldx #0
comout	lda cmdstr,x
	cmp #255
	beq com1
	jsr write
	inx
	jmp comout
com1	jmp clrchn
empty	ldx #comm
	jsr chkout
	lda #<buftxt
	ldy #>buftxt
	jsr strout
	jmp clrchn
dirin	ldx #work
	jmp chkin
getnext	jsr dirin
	jsr input
	sta next
	jsr input
	sta next+1
	jmp clrchn
dump	jsr dirin
	ldx #0
dump1	jsr input
	sta buffer,x
	inx
	bne dump1
	jmp clrchn
bufshow	ldx #0
	lda #1
	sta quote
buf1	lda buffer,x
	cmp #cr
	bne nocr
	lda #"m"
cr1	pha
	lda #1
	sta revers
	pla
	jsr write
	lda #0
	sta revers
	jmp buf2
nocr	cmp #scr
	bne noscr
	lda #"M"
	bne cr1
noscr	cmp #20
	bne nodel
	lda #"t"
	bne cr1
nodel	jsr write
buf2	inx
	stx quote
	bne buf1
	rts
init	jsr getx
	stx track
	jsr getx
	stx sektor
	jsr testpar
	jsr opendir
	jsr sendcmd
	jsr getnext
	jsr empty
	jsr dump
	jsr clsdir
	jmp bufshow
directory	lda #2
	ldx #<dirtxt
	ldy #>dirtxt
	jsr setnam
	ldx #drive
	lda #work
	ldy #0
	jsr setpar
	jsr open
	lda #0
	sta status
	ldx #work
	jsr chkin
	ldy #3
dir1	sty tmp
	jsr input
	sta tmp+1
	ldy status
	bne dir4
	jsr input
	ldy status
	bne dir4
	ldy tmp
	dey
	bne dir1
	ldx tmp+1
	jsr axout
	jsr space
dir3	jsr input
	ldy status
	bne dir4
	tax
	beq dir2
	jsr write
	bcc dir3
dir2	jsr return
	ldy #2
	bne dir1
dir4	jsr clrchn
	lda #work
	jmp close
holmax	jsr getx
testsek	cpx #36
	bcc hol3
ill	jmp illquan
hol3	cpx #0
	beq ill
	txa
	ldx #4
hol2	dex
	cmp wechs,x
	bcc hol2
	lda sekt,x
	sta next
	rts
testpar	ldx track
	jsr testsek
	cmp sektor
	bcc ill
	rts
